﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Bussiness.Service;

namespace Bussiness.View.BackEnd
{
    public partial class MG_Orders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Appcontex app = (Appcontex)Session["app"];
            string action = Request.Params.Get("Action");
            string id = Request.Params.Get("ID");
            if (action != null && id != null)
            {
                if (action == "Delete")
                {
                    if (app.IsAdmin == false)
                    {
                        MessageBox mgb = new MessageBox();
                        mgb.Alert("Lỗi", "Bạn không có quyền xóa hóa đơn này.");
                        mgb.Show();
                    }
                    else
                    {
                        new Order_Service().deleteHoaDon(int.Parse(id));
                        MessageBox msg = new MessageBox();
                        msg.Alert(" ", "Xóa thành công");
                        msg.Show();
                    }
                }
            }

            //if (!IsPostBack)
            //{
            //    HeaderOrder header = new HeaderOrder();
            //    header.Date = new Order_Service().GetLatestOrder();
            //    DSHoaDon_Store.DataSource = new Order_Service().SearchOrder(header);
            //    DSHoaDon_Store.DataBind();
            //}
        }

        public void Search(object sender, DirectEventArgs e)
        {
            HeaderOrder header = new HeaderOrder();
            header.PhoneCus = tk_soDT.Text;
            if (tk_NgayBan.IsEmpty == false)
                header.Date = tk_NgayBan.SelectedDate;
            header.NameCus = tk_tenKH.Text;

            DSHoaDon_Store.DataSource = new Order_Service().SearchOrder(header);
            DSHoaDon_Store.DataBind();
        }


        


    }
}
